package com.xiaomili.halfsugar.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.xiaomili.halfsugar.R;
import com.xiaomili.halfsugar.bean.ManifestBean;

/**
 * 搜索页面---GridView清单适配器
 * Created by Administrator on 2016/7/20.
 */
public class SearchManifestGridView_Adapter extends BaseAdapter{
    private Context mContext;
    private ManifestBean mManifestBean;
    public SearchManifestGridView_Adapter(Context mContext, ManifestBean mManifestBean){
        this.mContext=mContext;
        this.mManifestBean=mManifestBean;
    }
    @Override
    public int getCount() {
        return mManifestBean==null?0:mManifestBean.data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ManifestGridView manifestGridView=null;
        if (convertView==null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.manifest_gridview_adapter, parent, false);
            manifestGridView=new ManifestGridView(convertView);
            convertView.setTag(manifestGridView);
        }else {
            manifestGridView= (ManifestGridView) convertView.getTag();
        }
        Picasso.with(mContext).load(mManifestBean.data.get(position).icon).into(manifestGridView.imageView);
        manifestGridView.tv1.setText(mManifestBean.data.get(position).name);
        manifestGridView.tv2.setText(mManifestBean.data.get(position).en_name);
        return convertView;
    }
    private class ManifestGridView{
        private ImageView imageView;
        private TextView tv1,tv2;
        public ManifestGridView(View convertView) {
            imageView= (ImageView) convertView.findViewById(R.id.manifest_gridview_adapter_img);
            tv1= (TextView) convertView.findViewById(R.id.manifest_gridview_adapter_tv1);
            tv2= (TextView) convertView.findViewById(R.id.manifest_gridview_adapter_tv2);
        }
    }
}
